import HistoryUtil from 'utils/historyUtil';

export default {
  created() {
    window.addEventListener('wxshow', () => {
      HistoryUtil.clear();

      let actionData = window.actionData;
      if (actionData === undefined) {
        if (this.pageType === 'circle') {
          this.toResetCircleLogData();
        }
        return;
      }
      delete window.actionData;

      let type = actionData.type;
      if (type === 'toPage') {
        let url = actionData.data.url;
        let curUrl = HistoryUtil.getCurrentUrl();
        if (url !== curUrl) {
          location.href = url;
        } else {
          if (this.$refs['sysComp']) {
            let fun = this.$refs['sysComp'].resetData;
            if (fun) {
              fun();
            }
          }
        }
      } else {
        if (this.$refs['sysComp']) {
          let fun = this.$refs['sysComp'][type];
          if (fun) {
            fun(actionData.data);
          }
        }
      }
    });
  },

  methods: {
    toResetCircleLogData() {
      let spaceId = this.spaceId;
      if (spaceId === null) {
        return;
      }
      this.spaceId = null;
      this.$refs['sysComp'].resetCircleZoneLog(spaceId);
    }
  }
}
